package bdd;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Stack;
import modele.ChaineDeCaracteres;


/**
 *Cette classe permet d'établir le lien avec la base de données (au niveau des phrases)
 * et le jeu
 * 
 * @author flo
 */
public class DAOPhrase {

    public Connection c = null;
    public Statement stmt = null;

    public Stack<ChaineDeCaracteres> getPhrases(Integer n) throws SQLException {
        c = ConnecterBase.Connect();
        stmt = c.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM PHRASES ORDER BY RANDOM() LIMIT "
                + n.toString()
                + ";");
        Stack<ChaineDeCaracteres> s = new Stack<ChaineDeCaracteres>();
        while (rs.next()) {
            s.add(new ChaineDeCaracteres(rs.getString("PHRASE"), rs.getInt("VALEUR")));
     
        }

        rs.close();
        stmt.close();
        c.close();
        
        return s;
    }

}
